package com.heima.controller;


import com.heima.pojo.TbVmType;
import com.heima.pojo.vo.PageResponse;
import com.heima.service.ITbVmTypeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 售货机类型表 前端控制器
 * </p>
 *
 * @author nan
 * @since 2024-06-10
 */
@RestController
@RequestMapping("/api/vm-service/vmType")
public class TbVmTypeController {

    @Autowired
    private ITbVmTypeService vmTypeService;

    @GetMapping("/search")
    @ApiOperation("设备搜索")
    public PageResponse<TbVmType> getByPage(@RequestParam Integer pageIndex,
                                            @RequestParam Integer pageSize,
                                            @RequestParam(required = false) String name) {
        return vmTypeService.getByPage(pageIndex, pageSize, name);
    }

    @PostMapping
    @ApiOperation("新增设备类型")
    public Boolean addVmType(@RequestBody TbVmType vmType) {
        return vmTypeService.save(vmType);
    }

    @PutMapping("/{typeId}")
    @ApiOperation("修改设备类型")
    public Boolean updateVmType(@PathVariable Integer typeId, @RequestBody TbVmType vmType) {
        return vmTypeService.updateById(vmType);
    }

    @DeleteMapping("/{typeId}")
    @ApiOperation("删除设备类型")
    public Boolean deleteVmType(@PathVariable Integer typeId) {
        return vmTypeService.removeById(typeId);
    }
}
